<?php
/**
 * Created by PhpStorm.
 * User: 田家强
 * Date: 2017/4/2
 * Time: 13:41
 */

namespace Home\Controller;


use Think\Controller;

class BaseContoller extends Controller
{
    //构造方法，继承购物车
    protected $cartData;
    public function  __construct()
    {
        parent::__construct();
        $this->cartData = $_SESSION['cart'];
        $Cartl = $this->cartData;
        //dd($Cartl['goods']);
        $this->assign('Cartl',$Cartl);


    }

    public function index(){
        $this->assign('data',$this->cartData);

        $this->display();
    }
//    public function __construct()
//    {
//        parent::__construct();
//        if(method_exists($this,'__init'))
//        {
//            $this->__init();
//        }
//        $data =   $_SESSION['cart'];
//        if(!session('uid')){
//            $this->error('请登录！',u('home/login/index'));
//        }
//    }
    public function store(model $Model,$data,$url,\Closure $callback=null)
    {

//      $Model  = new ConfigModel(), $data =I('post.');
        $res = $Model->store($data);
        if($res[ 'valid' ] == 'success' && $callback instanceof \Closure)
        {
            $callback($res);
        }
        $this->message($res,$url);
    }

    public function message($res,$url){
        if($res['valid']=='success'){
            $this->success($res['msg'],$url);exit;
        }else{
            $this->error($res['msg'],$url);exit;
        }
    }

// 模糊查询
    public function query(){
        $post=$_POST['query'];//搜索内容
	    //dd($post);
        $data=m('category');//数据库数据
//        dd($data);
        $where['cname'] = array('like', "%$post%");
        $finalData=$data->where($where)->select();
//        dd($finalData);
        echo $finalData[0]['cid'];
    }


}